<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>点击地图拾取坐标</title>
</head>

{% include 'admin/common/header.html' %}
<script charset="utf-8" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
<script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77"></script>
<style type="text/css">
    html,
    body {
        height: 100%;
        margin: 0px;
        padding: 0px;
    }

    #container {
        width: 100%;
        height: 100%;
    }

    #info {
        position: absolute;
        left: 20px;
        top: 20px;
        font-size: 14px;
        background: #FFF;
        width: 270px;
        padding: 10px;
        border-radius: 3px;
    }
</style>

<body onload="initMap()">
<div id="container"></div>
<div id="info">当前点击坐标为：<span id="position"></span></div>

{% include 'admin/common/footer.html' %}
{#<script src="http://libs.baidu.com/highcharts/2.2.5/highcharts.js"></script>#}
<script>
    {#const xadmin = require("../../static/admin/component/layui/layui");#}
    layui.use(['upload', 'form', 'jquery', 'layer'], function () {
        let form = layui.form
        let $ = layui.jquery
        let layer = layui.layer


        window.closeWindow = function () {
            var userAgent = navigator.userAgent;
            if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Chrome") != -1) {
                location.href = "about:blank";
            } else {
                window.opener = null;
                window.open('', '_self');
            }
            window.close();
        }

        window.initMap = function () {
            var position = document.getElementById("position");

            var center = new TMap.LatLng(39.984104, 116.307503);//设置中心点坐标
            //初始化地图
            var map = new TMap.Map("container", {
                center: center
            });

            var lat;//纬度
            var lng;//经度

            //绑定点击事件
            map.on("click", function (evt) {
                console.log('evt:', evt)
                lat = evt.latLng.getLat().toFixed(6);
                lng = evt.latLng.getLng().toFixed(6);
                position.innerHTML = lat + "," + lng;

                {#    添加ajax#}
                $.ajax({
                    url: '{{ url_for('wxstores.addmap') }}',
                    data: {
                        lat: lat,
                        lng: lng
                    },
                    type: 'POST',
                    dataType: 'json',
                    success: function () {
                        window.href = '{{ url_for('wxstores.main') }}';
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.location.reload(); //刷新腹肌窗口
                        parent.layer.close(index); //再执行关闭
                        {#window.add()#}
                        {#window.history.back()#}
                        {#xadmin.close();//关闭当前的frame#}
                        {#var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引#}
                        {#parent.layer.close(index); //再执行关闭#}
                        {#window.href = '{{ url_for('wxstores.add') }}';#}
                        {#layer.close()#}
                        {#closeWindow()#}
                        {#xadmin.father_reload();//刷新父窗口#}
                    }
                })

            })

        }

    {#  window.add = function () {#}
    {#  layer.open({#}
    {#    type: 2,#}
    {#    title: '新增商品',#}
    {#    shade: 0.1,#}
    {#    area: ['850px', '530px'],#}
    {#    content: '/wxstores/add'#}
    {#  })#}
    {#//}#}

    })
</script>


</body>

</html>